﻿using System;
using System.Collections.Generic;
using Algoritmia.DataStructures.Maps;

namespace Algoritmia.DataStructures.DoubleEndedPriorityMaps
{
    public class MinMaxIntervalHeapMap<TKey,TValue> : IntervalHeapMap<TKey,TValue>
        where TValue : IComparable<TValue>
    {
        public MinMaxIntervalHeapMap(IEnumerable<KeyValuePair<TKey,TValue>> items = null,
                                     int capacity = 0,
                                     Func<int,IMap<TKey,int>> createMap = null,
                                     Func<IMap<TKey,int>,TKey,IMap<TKey,int>> redimensionMap = null)
            : base(items,capacity,createMap: createMap, redimensionMap: redimensionMap)
        {
        }

        public KeyValuePair<TKey, TValue> GetMinimum()
        {
            return GetOptimal();
        }

        public TKey GetMinimumKey()
        {
            return GetOptimal().Key;
        }

        public TValue GetMinimumValue()
        {
            return GetOptimal().Value;
        }

        public KeyValuePair<TKey, TValue> ExtractMinimum()
        {
            return ExtractOptimal();
        }

        public TKey ExtractMinimumKey()
        {
            return ExtractOptimal().Key;
        }

        public TValue ExtractMinimumValue()
        {
            return ExtractOptimal().Value;
        }

        public KeyValuePair<TKey, TValue> GetMaximum()
        {
            return GetWorst();
        }

        public TKey GetMaximumKey()
        {
            return GetWorst().Key;
        }

        public TValue GetMaximumValue()
        {
            return GetWorst().Value;
        }

        public KeyValuePair<TKey, TValue> ExtractMaximum()
        {
            return ExtractWorst();
        }

        public TKey ExtractMaximumKey()
        {
            return ExtractWorst().Key;
        }

        public TValue ExtractMaximumValue()
        {
            return ExtractWorst().Value;
        }

        public override string ToString()
        {
            return String.Format("{0} <{1},{2}> [{3}]", GetType().Name, typeof(TKey).Name, typeof(TValue).Name,
                                 string.Join(",", this));
        }
    }
}
